package net.cassite.daf4j.jpa;

import net.cassite.daf4j.ds.TxManager;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 * JPA的事务管理器
 */
public class JPATxManager implements TxManager {
        private final EntityManager entityManager;
        private EntityTransaction tx;

        public JPATxManager(EntityManager entityManager){
                this.entityManager=entityManager;
        }
        @Override
        public void txBegin() {
                tx=entityManager.getTransaction();
                tx.begin();
        }

        @Override
        public void txCommit() {
                tx.commit();
        }

        @Override
        public void txRollback() {
                tx.rollback();
        }
}
